package controller;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import service.StudentManager;
import service.impl.StudentManagerImpl;
import vo.Student;

@Controller
public class StudentManagerController {
	
	private StudentManager sm = new StudentManagerImpl();
	
	@RequestMapping("/login")
	public String login(String st_number,String st_passwd,HttpServletRequest request){
		System.out.println(st_number);
		Student student = sm.login(st_number, st_passwd);
		//System.out.println("this is controller : " + student.getSt_number());
		if(student!=null){
			
			request.getSession().setAttribute("student",student);
			
			return "loginSuccess";///WEB-INF/jsp/loginSuccess.jsp
			
		}else{
			return "login";
		}
		
		
		//return "loginSuccess";
	}
	
	@RequestMapping("/regist")
	
	public String regist(Student student,HttpServletRequest request){
		
		//System.out.println("this is controller : " + student.getSt_passwd());
		//System.out.println("this is controller : " + student.getSt_number());
		int rs = 0;
		try {
			rs = sm.regist(student);
			
			request.getSession().setAttribute("student",student);
			
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		if(rs >0){
			//return "registSuccess";
			return "redirect:/registSuccess.jsp";
		}else{
			return "regist";
		}
	}
	
	

}
